//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#ifndef __SAGUTTARUIS__ATOMICS__H_
#define __SAGUTTARUIS__ATOMICS__H_

//== INCLUDES ========================================================================

#include "sagittarius/core/SagittariusCore.h"

#ifdef __cplusplus
extern "C" {
#endif

//Fetch and Add:
uint32 sg_fad32(uint32 volatile *v, int32 delta);
uint32 sg_fadd32(uint32 volatile *v, int32 delta);
uint32 sg_sfad32(int32 volatile *v, int32 delta);
uint32 sg_sfadd32(int32 volatile *v, int32 delta);

//Compare and Swap:
uint64 sg_cas16(uint16 volatile *v, uint16 t, uint16 s);
uint64 sg_cas32(uint32 volatile *v, uint32 t, uint32 s); //change retval to uint32 for cryin' out loud
uint64 sg_scas32(int32 volatile *v,  int32 t,  int32 s); //exact same asm as unsigned but avoids compiler warnings
uint64 sg_cas64(uint64 volatile *v, uint64 t, uint64 s);

//CAS for pointers
//void* sg_casptr(volatile void **v, void* t, void* s);
#if SAGITTARIUS_ARCH == SAGITTARIUS_ARCH_64
    #define sg_casptr(v, t, s) sg_cas64((uint64*)v, (uint64)t, (uint64)s)
#else
    #define sg_casptr(v, t, s) sg_cas32((uint32*)v, (uint32)t, (uint32)s)
#endif

#ifdef __cplusplus
}//extern "C"
#endif

#endif
